import {AfterContentInit, Component, ContentChild, ContentChildren, OnInit, QueryList, TemplateRef, ViewContainerRef} from '@angular/core';
import {cars} from '../../cars';

@Component({
  selector: 'app-a-1',
  templateUrl: './a-1.component.html',
  styleUrls: ['./a-1.component.css']
})
export class A1Component implements OnInit, AfterContentInit {
  cars: any;
  columns: any;
  config: any;
  buttons: any;
  myButtons: any;
   name1: TemplateRef<any>;
   name2: TemplateRef<any>;
   name3: TemplateRef<any>;
  @ContentChildren(TemplateRef) childrenList: QueryList<any>;
  constructor(private vcRef: ViewContainerRef) {
  }

  ngOnInit() {
    this.config = [
      {type: 'input', label: '姓名：', name: 'name', placeholder: '请输入文字'},
      {type: 'time', label: '时间', name: 'startTime', placeholder: '请选择时间'},
      {
        type: 'select', label: '性别：', name: 'sex',
        options: [
          {label: '男', value: 1},
          {label: '女', value: 2}
        ],
        placeholder: '请选择性别'
      }
    ];
    this.columns = [
      {field: 'vin', header: '车名'},
      {field: 'year', header: '生产年代'},
      {field: 'brand', header: '品牌'},
      {field: 'color', header: '颜色'},
      {field: 'time', header: '当前时间', type: 'time'},
      {field: 'buttons', header: '操作', type: 'button'}
    ];
    this.cars = cars;
    this.myButtons = [
      {type: 'add', label: '新增'},
      {type: 'delete', label: '删除'},
      {type: 'update', label: '修改'},
      {type: 'detail', label: '查看'}
    ];
    this.cars.forEach(e => {
      e.buttons = this.myButtons;
    });
    console.log(new Date().getTime());
  }
  ngAfterContentInit(): void {
    this.childrenList.forEach((item) => {
      switch (Object.getOwnPropertyNames(item._def.references)[0]) {
        case 'name1':
          this.name1 = item;
          break;
        case 'name2':
          this.name2 = item;
          break;
        case 'name3':
          this.name3 = item;
          break;
      }
    });
  }

  clickBut(event) {
    console.log(event);
  }
}
